//
//  ViewController.swift
//  Swift-30-demo
//
//  Created by apple on 2021/11/22.
//

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    var listView: UITableView?
    let titleArray: NSArray = ["CustomFont", "Watch's Demo", "FindMyPosition", "LimitInputText", "PullToRefresh", "PullToRefreshDemo", "VideoPlayer", "SimplePhotoBrowser"]
    let detailTitleArray: NSArray = ["自定义字体样式", "练习定时器，实现计时功能", "掌握经纬度以及地理位置的获取", "掌握监听以及输入字数限制的使用方法", "掌握下拉刷新的实现方法", "掌握三方GTMRefreshDemo的使用方法", "掌握播放器的使用方法", "图片浏览与缩放"]

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        self.view.backgroundColor = UIColor.white
        self.navigationItem.title = "Swift Demo"
        
        listView = UITableView.init(frame: self.view.frame, style: .plain)
        listView?.delegate = self
        listView?.dataSource = self
        self.view.addSubview(listView!)
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
        var config = cell.defaultContentConfiguration()
        config.text = (titleArray[indexPath.row] as? String)
        config.textProperties.font = UIFont(name: "Savoye LET", size: 20) ?? UIFont.systemFont(ofSize: 20)
        config.textProperties.color = UIColor.blue
        config.secondaryText = (detailTitleArray[indexPath.row] as! String)
        config.secondaryTextProperties.font = UIFont.systemFont(ofSize: 16)
        config.secondaryTextProperties.color = UIColor.purple
        cell.contentConfiguration = config
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 80.0
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        print("点击的行数为\(indexPath.row)")
        switch indexPath.row {
        case 0:
            let fontVC = CustomFont()
            fontVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(fontVC, animated: true)
            break
        case 1:
            let watchVC = WatchTimer()
            watchVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(watchVC, animated: true)
            break
        case 2:
            let findPositionVC = FindMyPosition()
            findPositionVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(findPositionVC, animated: true)
            break
        case 3:
            let limitInputVC = LimitInputText()
            limitInputVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(limitInputVC, animated: true)
            break
        case 4:
            let pullToRefreshVC = PullToRefresh()
            pullToRefreshVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(pullToRefreshVC, animated: true)
            break
        case 5:
            let refreshVC = PullToRefreshDemo()
            refreshVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(refreshVC, animated: true)
            break
        case 6:
            let videoPlayerVC = VideoPlayer()
            videoPlayerVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(videoPlayerVC, animated: true)
            break
        case 7:
            let photoBrowserVC = SimplePhotoBrowser()
            photoBrowserVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(photoBrowserVC, animated: true)
            break
        default:
            print("暂无定义，待续...")
        }
    }
}

